﻿<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>数据分析--报告生成--上传模板</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <script type="text/javascript" src="/static/js/main-page/echarts.min.js"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style type="text/css"></style>
</head>
<body onload="onLoad()">
<div class="mini-fit">
    <div style="margin: 20px;">
        <form id="form1" method="post">
            <div id="editform1" class="form">
                <input id="id" name="id" class="mini-hidden" value="${id!''}" />
                <table class="form-table" width="100%">
                    <tr>
                        <td width="30%" align="right" style="line-height: 30px;padding-top: 10px;">
                            模板名称:
                        </td>
                        <td width="70%">
                            <input class="mini-textbox" value="${tname!''}" id="tname" name="tname" required="true" />
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" align="right">模板类型:</td>
                        <td>
                            <input name="ttype" id="ttype" value="${ttype!''}" class="mini-combobox" style="width: 200px" required="true"
                                   textField="codeName" valueField="codeId" emptyText="请选择..."
                                   url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=3_11" />
                        </td>
                    </tr>
                    <tr>
                        <td width="30%" align="right" style="line-height: 30px;padding-top: 10px;">是否包含图表:</td>
                        <td width="70%">
                            <input class="mini-radiobuttonlist" value="${containchart!''}" id="containchart" name="containchart"
                                   data="[{id:1,text:'是'},{id:2,text:'否'}]" valueField="id" textField="text" onvaluechanged="onContainPic"
                                   required="true" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <form id="form2" method="post">
            <div id="fileform2" class="form" style="width: 100%">
                <table class="form-table" width="100%">
                    <tr>
                        <td width="30%" align="right" style="line-height: 50px;">
                            选择模板:
                        </td>
                        <td width="70%">
                            <input type="file" id="templateFile" name="templateFile" />
                        </td>
                    </tr>
                    <#if tfilename??>
                        <tr>
                            <td width="30%" align="right" style="line-height: 50px;">
                            </td>
                            <td width="70%">
                                <span style="color: #8C8C8C">${tfilename!''}</span>
                            </td>
                        </tr>
                    </#if>
                </table>
            </div>
        </form>
        <form id="form3" method="post" style="display: none">
            <div id="form2_file" class="form" style="width: 100%;">
                <table class="form-table" width="100%">
                    <tr>
                        <td width="30%" align="right" style="line-height: 50px;">
                            选择图表文件:
                        </td>
                        <td width="70%">
                            <input type="file" id="chartFile" name="chartFile" />
                        </td>
                    </tr>
                    <#if chartfilename??>
                        <tr>
                            <td width="30%" align="right" style="line-height: 50px;">
                            </td>
                            <td width="70%">
                                <span style="color: #8C8C8C">${chartfilename!''}</span>
                            </td>
                        </tr>
                    </#if>
                </table>
            </div>
        </form>
    </div>
</div>
<div>
    <br />
</div>
<div style="padding:2px;margin: 0 auto;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="close()">取消</a>
</div>
<div>
    <br />
</div>

<script type="text/javascript">

    mini.parse();
    var chartObj = mini.get("containchart");
    var idObj = mini.get("id");
    var form = new mini.Form("form1");

    function onLoad() {
        onContainPic();
    }

    function onContainPic() {
        var chartVal = chartObj.getValue();
        if (chartVal == "1") {
            document.getElementById("form3").style.display = "block";
        } else {
            document.getElementById("form3").style.display = "none";
        }
    }

    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var idVal = idObj.getValue();
        var templateVal = document.getElementById("templateFile").value;
        if (!templateVal && !idVal) {
            mini.alert("请选择模板文件");
            return;
        }
        if (templateVal) {
            var templateUrl = "/azbj/sjtjfx/scbg/uploadtemplate/uploadTemplateFile";
            var templateData = uploadFileWithId(templateUrl, "form2");
            data.tfilename = templateData.fileName;
            data.tpath = templateData.filePath;
        }

        var chartCheck = chartObj.getValue();
        var chartVal = document.getElementById("chartFile").value;
        if (chartCheck == "1" && !chartVal) {
            mini.alert("请选择图表文件");
            return;
        }
        if (chartVal) {
            var chartUrl = "/azbj/sjtjfx/scbg/uploadtemplate/uploadChartFile";
            var chartData = uploadFileWithId(chartUrl, "form3");
            data.chartpath = chartData.filePath;
            data.chartfilename = chartData.fileName;
        }
        var json = mini.encode(data);
        $.ajax({
            url: "/azbj/sjtjfx/scbg/uploadtemplate/saveTemplate",
            type: "post",
            data: {data: json},
            async: false,
            success: function (result) {
                mini.alert(result.data);
                close("close");
            }
        });
    }

    function uploadFileWithId(url, formName) {
        var path = "";
        var formData = new FormData(document.getElementById(formName));
        $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: url,
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            dataType: "json",
            async: false,
            error: function (result) {

            },
            success: function (result) {
                path = result.data;
            }
        });
        return path;
    }

    function close(action) {
        if (window.CloseOwnerWindow) {
            window.CloseOwnerWindow(action);
        } else {
            window.close();
        }
    }
</script>
</body>
</html>